home *** CD-ROM | disk | FTP | other *** search
/ Your Choice 3 / Your Choice Software Collection 3.iso / prgmming / swag08 / savescrn.swg < prev    next >
Text File  |  1994-09-22  |  12KB  |  1 lines

  1. SWAGOLX.EXE (c) 1993 GDSOFT  ALL RIGHTS RESERVED 00003                                                                           1      08-24-9413:36ALL                      GABRIEL LAGOS            Save Dos Screen          SWAG9408    ╖¢1⌐    19     R    Program FancyWiper;π uses crt;ππ Typeπ   {I define the following type for all my virtual screens. Using thisπ    record allows me to write to any screen variable very easily}π   ScreenType = array [1..25,1..80] of recordπ        ch   : Char;π        Attr : Byte;π      end;ππ Varπ   {define a variable which points to the screen location. If you had a monoπ    card then the address would be $B000:0000.}π   Screen : ScreenType absolute $B800:0000;ππ   {Declare a variable to save your old DOS screen}π   OldScreen : ScreenType;π   {Declare a virtual screen}π   VirtScr : ScreenType;ππ   {This procedure is used to write text to a virtual screen. Nowπ    there are no problems writing to line 25! ;-) }π   Procedure MyWrite(var Scr : ScreenType; x,y : integer; st : String);π   varπ     t, xpos : integer;π   beginπ     xpos := 0;ππ     {exit proc if y not in screen limits}π     if not (y in [1..25]) thenπ       exit;ππ     while (xpos+1 <= length(st)) and (xpos+x <=80) doπ       beginπ         with Scr[y, xpos+x] doπ           beginπ             ch := St[xpos+1];π             attr := TextAttr;π           end;π         inc(xpos);π       end;π   end;ππ   {A kludgy ClrScr for a virtual screen }π   Procedure MyClrScr(var Scr : ScreenType);π   beginπ     fillchar(Scr, Sizeof(scr), 0);π   end;ππ   {Simple demonstration of a fancy effect. There's a lot more where this cameπ   from!!}π   Procedure Wipe(Scr : ScreenType; Left : Boolean; DelayTime : Word);π   varπ     xstep,x,y : integer;π   beginπ     if Left thenπ       beginπ         xstep := -1;π         x := 80;π       endπ     elseπ       beginπ         xstep := 1;π         x := 1;π       end;ππ     while x in [1..80] doπ       beginπ         for y := 1 to 25 doπ           Screen[y,x] := Scr[y,x];π         Delay(DelayTime);π         inc(x,xstep);π       end;π   end;πππ Beginπ   {Save the dos screen first}π   OldScreen := Screen;ππ   {Now go and do whatever you want with the screen}π   TextColor(Green);π   MyClrScr(VirtScr);π   MyWrite(VirtScr,10,10,'Hello there! Hows everything!  That should make this line long enough');π   MyWrite(VirtScr,10,13,'Whats your name : ');π   Wipe(VirtScr,True,30);π   GotoXy(28,13);π   TextColor(White);π   Readln;ππ   {Now to restore the old screen}π   Wipe(OldScreen,False,20);π End.π               2      08-24-9413:56ALL                      JUAN JOSE VERGARA        Screen Save Object       SWAG9408    o┬J┴    16     R   { - SCREEN.PAS -}πunit screen;πInterfaceπuses crt,dos;π  typeπ       ScreenRec = Recordπ         Character:Byte;π         Attribute:Byte;π       end;π       SnapShot = recordπ         Screen:array[1..4000] of ScreenRec;π         StoreX:byte;π         StoreY:byte;π       end;π       ScreenStore=objectπ         Memory:SnapShot;π         constructor Init(InitX,InitY,InitChar,InitColor:byte);π         procedure storescreen;π         procedure restorescreen;π       end;π       ScreenStorePointer = ^ScreenStore;πImplementationπ  CONSTRUCTOR ScreenStore.Init(InitX,InitY,InitChar,InitColor:byte);π    {** Initializes to Cleared Screens **}π    varπ      Count:integer;π    beginπ      Count:=1;π      while Count<=4000 doπ        beginπ          FillChar(Memory.Screen[Count].Character,π            SizeOf(Memory.Screen[Count].Character),InitChar);π          FillChar(Memory.Screen[Count].Attribute,π            SizeOf(Memory.Screen[Count].Attribute),InitColor);π          inc(Count);π        end;π      Memory.StoreX:=InitX;π      Memory.StoreY:=InitY;π    end;π  PROCEDURE ScreenStore.StoreScreen;π    varπ      MonoAddress:  char absolute $B000:0000;π      ColorAddress: char absolute $B800:0000;π      beginπ        if lastmode=mono thenπ          move(monoAddress,Memory.Screen,8000)π        elseπ          move(colorAddress,Memory.Screen,8000);π        Memory.StoreX:=WhereX;π        Memory.StoreY:=WhereY;π      end;π  {STORESCREEN}π  PROCEDURE ScreenStore.RestoreScreen;π    varπ      MonoAddress:  char absolute $B000:0000;π      ColorAddress: char absolute $B800:0000;π      beginπ        if lastmode=mono thenπ          move(Memory.Screen,monoAddress,8000)π        elseπ          move(Memory.Screen,colorAddress,8000);π        gotoxy(Memory.StoreX,Memory.StoreY);π      end;π  beginπ  end.π                                                                                                                        3      08-25-9409:12ALL                      CYRUS.PATEL@NITEBEATS.COMSuper Screen Save        SWAG9408    Sl»R    55     R   {π:   Is there a way to save the current text screen so you can call itπ: up later? (ie: Either save the screen so you can display something elseπ: in text, then bring back the first page, or to display graphics, thenπ: bring back the old text screen.)  Also, is there a way to dumb the screenπ: to disk?ππHere's the stuff i use... (It works from TP 4.0 and up)π}ππTypeπ    ScreenRecord =π      Recordπ        X, Y: Byte; {x,y coord. of cursor}π        Screen: Pointerπ      End;ππ  Varπ    OriginalScreen: ScreenRecord;πππFunction QueryAdapterType: AdapterType;ππ  Varπ    Code: Byte;π    Regs: Registers;ππ  Beginπ    Regs.AH := $1A; { Attempt to call VGA Identify Adapter Function }π    Regs.AL := $00; { Must clear AL to 0 ... }π    Intr($10, Regs);π    If Regs.AL = $1A then { ...so that If $1A comes back in AL... }π      Begin { ...we know a PS/2 video BIOS is out there. }π      Case Regs.BL of { Code comes back in BL }π        $00:π          QueryAdapterType := None;π        $01:π          QueryAdapterType := MDA;π        $02:π          QueryAdapterType := CGA;π        $04:π          QueryAdapterType := EGAColor;π        $05:π          QueryAdapterType := EGAMono;π        $07:π          QueryAdapterType := VGAMono;π        $08:π          QueryAdapterType := VGAColor;π        $0A, $0C:π          QueryAdapterType := MCGAColor;π        $0B:π          QueryAdapterType := MCGAMonoπ        elseπ          QueryAdapterType := CGAπ        End { Case }π      Endπ    elseπ    { Next we have to check for the presence of an EGA BIOS: }π      Beginπ      Regs.AH := $12; { Select Alternate Function service }π      Regs.BX := $10; { BL=$10 means return EGA information }π      Intr($10, Regs); { Call BIOS VIDEO }π      If Regs.BX <> $10 then { BX unchanged means EGA is NOT there...}π        Beginπ        Regs.AH := $12; { Once we know Alt Function exists... }π        Regs.BL := $10; { ...we call it again to see If it's... }π        Intr($10, Regs); { ...EGA color or EGA monochrome. }π        If Regs.BH = 0 thenπ          QueryAdapterType := EGAColorπ        elseπ          QueryAdapterType := EGAMonoπ        Endπ      else { Now we know we have an EGA or MDA: }π        Beginπ        Intr($11, Regs); { Equipment determination service }π        Code := (Regs.AL and $30) Shr 4;π        Case Code ofπ          1:π            QueryAdapterType := CGA;π          2:π            QueryAdapterType := CGA;π          3:π            QueryAdapterType := MDAπ          elseπ            QueryAdapterType := CGAπ          End { Case }π        Endπ      Endπ  End;πππFunction DeterminePoints: Integer;ππ  Varπ    Regs: Registers;ππ  Beginπ    Case QueryAdapterType ofπ      CGA:π        DeterminePoints := 8;π      MDA:π        DeterminePoints := 14;π      EGAMono, { These adapters may be using any of }π      EGAColor, { several different font cell heights, }π      VGAMono, { so we need to query the BIOS to find }π      VGAColor, { out which is currently in use. }π      MCGAMono, MCGAColor:π        Beginπ        With Regs doπ          Beginπ          AH := $11; { EGA/VGA Information Call }π          AL := $30;π          BL := 0π          End;ππ        Intr($10, Regs);π        DeterminePoints := Regs.CXπ        Endπ      End { Case }π  End;πππProcedure SaveScreen(Var StashPtr: Pointer);ππ  Typeπ    VidPtr = ^VidSaver;π    VidSaver =π      Recordπ        Base, Size: Word;π        BufStart: Byteπ      End;ππ  Varπ    VidVector: VidPtr;π    StashBuf: VidSaver;π    VidBuffer: Pointer;π    Adapter: AdapterType;ππ  Beginπ    Adapter := QueryAdapterType;π    With StashBuf doπ      Beginπ      Case Adapter ofπ        MDA, EGAMono, VGAMono, MCGAMono:π          Base := $B000π        elseπ          Base := $B800π        End; { Case }π      Case DeterminePoints ofπ        8:π          Case Adapter ofπ            CGA:π              Size := 4000; { 25-line screen }π            EGAMono, EGAColor:π              Size := 6880 { 43-line screen }π            elseπ              Size := 8000 { 50-line screen }π            End; { Case }π        14:π          Case Adapter ofπ            EGAMono, EGAColor:π              Size := 4000; { 25-line screen }π            elseπ              Size := 4320 { 27-line screen }π            End; { Case }π        16:π          Size := 4000π        End; { Case }π      VidBuffer := Ptr(Base, 0)π      End;ππ    { Allocate heap for whole shebang }π    GetMem(StashPtr, StashBuf.Size + 16);π    { Here we move *ONLY* the VidSaver Record (5 bytes) to the heap: }π    Move(StashBuf, StashPtr^, Sizeof(StashBuf));π    { This casts StashPtr, a generic pointer, to a pointer to a VidSaver: }π    VidVector := StashPtr;π      { Now we move the video buffer itself to the heap.  The vide data isπ        written starting at the BufStart byte in the VidSaver Record, andπ        goes on for Size bytes to fit the whole buffer.  Messy but hey,π        this is PC land! }π    Move(VidBuffer^, VidVector^.BufStart, StashBuf.Size);π  End;πππProcedure RestoreScreen(StashPtr: Pointer);ππ  Typeπ    VidPtr = ^VidSaver;π    VidSaver =π      Recordπ        Base, Size: Word;π        BufStart: Byteπ      End;ππ  Varπ    DataSize: Word;π    VidVector: VidPtr;π    VidBuffer: Pointer;ππ  Beginπ    VidVector := StashPtr; { Cast generic pointer onto VidSaver pointer }π    DataSize := VidVector^.Size;π    { Create a pointer to the base of the video buffer: }π    VidBuffer := Ptr(VidVector^.Base, 0);π    { Move the buffer portion of the data on the heap to the video buffer: }π    Move(VidVector^.BufStart, VidBuffer^, VidVector^.Size);π    FreeMem(StashPtr, DataSize + 16)π  End;π(*ππHere's how you save a screen...ππ      With OriginalScreen doπ        Beginπ        X := WhereX; {save the x,y cursor positions...}π        Y := WhereY - 1;π        SaveScreen(Screen) {then the screen}π        End;ππHere's how you restore a screen...ππ    With OriginalScreen doπ      Beginπ      RestoreScreen(Screen); {restore the screen}π      GotoXY(X, Y) {go back to the orig. cursor position}π      End;ππ:   While we're at it, I might as well get all my questions out of myπ: system :)  First, is there a way to stop the program from crashing ifπ: someone enters a character instead of an integer (or any incompatibleπ: data types?)  I've been looking around but havn't found anything...ππThe best way is to read the number in as a string (characters), then useπthe procedure Val(), to convert it from a character string to numeric.ππ: And lastly, how do you stop the program from crashing if a user entersπ: a filename to load, and it doesn't exist?  I think this has somethingπ: to do with the doserror (is that the function name?  Don't recall offhand)π: but I couldn't get it to work.ππCheck to see if the file exists, before you open it (Reset)...  Here's aπquick function..ππFunction Exists(FileName: String): Boolean;ππ  Beginπ    Exists := FSearch(FileName, '') <> ''π  End;π*)π